/*
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * The software in this package is published under the terms of the GPL v2.0
 * license, a copy of which has been included with this distribution in the
 * LICENSE-GPL.txt file.
 */

package org.cemantika.management.drools.dao;

import java.util.List;

import org.cemantika.infrastructure.dao.BaseDao;
import org.cemantika.infrastructure.model.ContextUser;
import org.cemantika.management.drools.DroolsContextualManipulation;

/**
 * DaoDroolsContextualManipulation represents the implementation of data persistence layer of the
 * entity {@link DroolsContextualManipulation}.
 * 
 * @author andersonfellipe
 */
public class DaoDroolsContextualManipulation extends BaseDao<DroolsContextualManipulation> implements
        IDaoDroolsContextualManipulation {

    /**
     * Creates a new instance of DaoDroolsContextualManipulation.
     */
    public DaoDroolsContextualManipulation() {
        super();
    }

    /*
     * (non-Javadoc)
     * 
     * @see
     * org.cemantika.management.drools.dao.IDaoDroolsContextualManipulation#findByContextUser(org
     * .cemantika.infrastructure.model.ContextUser)
     */
    @SuppressWarnings({"restriction", "unchecked"})
    @Override
    public DroolsContextualManipulation findByContextUser(ContextUser contextUser) {
        List<DroolsContextualManipulation> droolsContextualManipulations =
                (List<DroolsContextualManipulation>) super.getHibernateTemplate().findByNamedParam(
                        "FROM DroolsContextualManipulation d WHERE d.contextUser = :contextUser",
                        new String[] {"contextUser"}, new Object[] {contextUser});
        if (droolsContextualManipulations.isEmpty()) {
            return null;
        }
        return droolsContextualManipulations.get(0);
    }

}
